﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using groupAnalyzer.model;
namespace groupAnalyzer
{
    public class NodeView
    {
        private Node node;
        private NodeConnectionMode state;

        private static string emptyStr(string str)
        {
            if (str.Equals(""))
            {
                return "-";
            }
            return str;
        }

        public IList<UserView> Users
        {
            get
            {
                IList<UserView> ret = new List<UserView>();
                IList<User> usersOfGroup = this.node.Members;
                foreach (User user in usersOfGroup)
                {
                    ret.Add(new UserView(user));
                }
                return ret;
            }
        }

        public string FQDN
        {
            get
            {
                return emptyStr(this.node.FQDN);
            }
        }

        public string State
        {
            get
            {
                switch (this.state)
                {
                    case NodeConnectionMode.cyclic:
                        return "Red";
                        break;

                }
                return "Transparent";
            }
        }

        public IList<NodeView> Items
        {
            get
            {
                IList<NodeView> childs = new List<NodeView>();
                if (this.state == NodeConnectionMode.cyclic)
                {
                    return null;
                }
                foreach (NodeConnection nodeConnection in this.node.Connections)
                {
                    childs.Add(new NodeView(nodeConnection.To, nodeConnection.Mode));
                }
                return childs;
                foreach (Node node in this.node.Childs)
                {
                    //childs.Add(new UserNodeView(node));
                }
                return childs;
            }
        }

        public string Name
        {
            get { return emptyStr(this.node.Name); }
        }

        public string Description
        {
            get { return emptyStr(this.node.Description); }
        }

        public string Email
        {
            get { return emptyStr(this.node.Email); }
        }

        public string GroupScope
        {
            get { return emptyStr(this.node.GroupScope); }
        }

        public string GroupType
        {
            get { return emptyStr(this.node.GroupType); }
        }

        public string Notes
        {
            get { return emptyStr(this.node.Notes); }
        }

        public NodeView(Node node, NodeConnectionMode mode)
        {
            this.state = mode;
            this.node = node;
        }
    }
}
